package com.bw.study.live;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import com.bw.study.databinding.ActivityMainBinding;

public class TestLieveDataActivity extends AppCompatActivity {

    private LiveDataBus<String>liveDataBus = new LiveDataBus<>();
    private ActivityMainBinding mainBinding;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         mainBinding =  ActivityMainBinding.inflate(LayoutInflater.from(this));
         setContentView(mainBinding.getRoot());
         liveDataBus.observe(this, new Observer<String>() {
             @Override
             public void onChanged(String s) {
                 Log.e("ZXY","onChanged:"+s);
             }
         });
         mainBinding.mainTv.setOnClickListener(new View.OnClickListener(){

             @Override
             public void onClick(View v) {
                  liveDataBus.postValue("shiyuan");
             }
         });
    }
}
